/**
 * Created by ZT on 2018/5/8 0008.
 */
  var machineTypeVue = new Vue({
        el:'#machineTypeVue',
       data:{
           dataTable:[],
           userContent:{
           },
           scanMessage:[],//浏览图片信息
           editRow:[],  //当前编辑的那行
           row:{
               page:1, //当前页
               per_page:20, //每页行数,
               total:''
           },
           select:[
               20,50,100,200
           ]
       },
    mounted:function () {
        this.load();
    },
    methods:{
        load:function () {
                // 设置参数
                $('[data-am-selected]').selected({
                    btnWidth: '200px',
                    btnSize: 'sm',
                    btnStyle: 'secondary',
                    dropUp:1
                });
                var target =this;
                var $selected = $('#userSelect');
                $selected.on('change', function() {
                    target.row.per_page = $(this).find('option').eq(this.selectedIndex).text();
                    target.loadMachineType();
                });
                target.loadMachineType();
        },
        loadMachineType:function () {
            var target = this;
            var url = 'machine-types';
            this.fetch({
                url : url,
                method : 'GET',
                params:{
                        page : target.row.page,
                    per_page : target.row.per_page
                },
            }).then(function (response) {
                var paginationTable = $("#paginationType");
                initPagination(response,url,paginationTable,target);
            });
        },
        submitAdd:function () {
            var target = this;
            var $form = $('#addFormUser');
            validateForm($form);/*验证方法，出现提示*/
            var params = this.editRow;
            var url = 'machine-types';
            target.fetch({
                url : url,
                method : 'post',
                data :params
            }).then(function (response) {
                console.log(response);
            });
        },
        addPicture:function (id) {
            var target = this;
            $('#file').click();
            // 选择图片之后直接上传
            $("#file").change(function(){
                $('#tid').val(id+"");
                target.upload_excel(id);
            })

        },
        upload_excel:function (id) {  //文件上传
            var url = 'machine-types'+'/'+params.id;
            target.fetch({
                url : url,
                method : 'PUT',
                data :params
            }).then(function (response) {
                console.log(response);
            });
        },
        showPicture:function (item) {
            this.scanMessage = item;
            var $modal = $('#myPicture');
            $modal.modal('open');
        },
        submitEdit:function () {
            var target = this;
            var $form = $('#form-with-tooltip');
            validateForm($form);/*验证方法，出现提示*/
            var params = this.editRow;
            var url = 'machine-types'+'/'+params.id;
            target.fetch({
                url : url,
                method : 'PUT',
                data :params
            }).then(function (response) {
                console.log(response);
            });
        },
        deleteClick:function (row) {
            var target = this;
            var url = 'machine-types'+'/'+row.id;
            loginKey=true;
            AMUI.dialog.confirm({
                title: '提示',
                content: '确定要删除这条记录吗？',
                onConfirm: function () {
                    target.fetch({
                        url : url,
                        method : 'DELETE',
                        params:{}
                    }).then(function (response) {
                        AMUI.dialog.tips({title: initString('提示'), content: initString('删除成功'),type:'success'});
                        target.load();
                    });
                },
                onCancel: function() {
                    console.log('onCancel')
                }
            })
        },
        editClick:function (row) {
            var target = this;
            var url='machine-types/'+row.id;
            target.fetch({
                url : url,
                method : 'get',
                params: ''
            }).then(function (response) {
                console.log(response.data.row);
                target.editRow = response.data.row;
            });
            var $modal = $('#my-edit');
            $modal.modal('open');
        }
        
    }



});